package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.PropagationCultivation;
import com.fsnbigdata.domain.PlantConservation;
import com.fsnbigdata.domain.QPropagationCultivation;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = PropagationCultivationRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = PropagationCultivationRepositoryCustom.class)
@Transactional(readOnly = true)
public class PropagationCultivationRepositoryImpl extends QueryDslRepositorySupportExt<PropagationCultivation> implements PropagationCultivationRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    PropagationCultivationRepositoryImpl() {
        super(PropagationCultivation.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SURVIVE_1 = "survive1";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SURVIVE_2 = "survive2";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SURVIVE_3 = "survive3";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String FILLING_DATE = "fillingDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PLANT_CONSERVATION = "plantConservation";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CULTIVATE_DATE_2 = "cultivateDate2";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String GROWTH_SITUATION = "growthSituation";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CULTIVATE_DATE_1 = "cultivateDate1";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String INTRO_NO = "introNo";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CULTIVATE_DATE_3 = "cultivateDate3";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String MATERIAL_TYPE = "materialType";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SURVIVAL_RATE = "survivalRate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CULTIVATE_SUBSTANCE = "cultivateSubstance";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CULTIVATE_DATE = "cultivateDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String MATERIAL_QUANTITY = "materialQuantity";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String RECORDER = "recorder";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CULTIVATE_NUMBER = "cultivateNumber";

    /**
     * TODO Auto-generated method documentation
     *
     * @param plantConservation
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<PropagationCultivation> findByPlantConservation(PlantConservation plantConservation, GlobalSearch globalSearch, Pageable pageable) {
        QPropagationCultivation propagationCultivation = QPropagationCultivation.propagationCultivation;
        JPQLQuery<PropagationCultivation> query = from(propagationCultivation);
        Assert.notNull(plantConservation, "plantConservation is required");
        query.where(propagationCultivation.plantConservation.eq(plantConservation));
        Path<?>[] paths = new Path<?>[] { propagationCultivation.plantConservation, propagationCultivation.introNo, propagationCultivation.materialType, propagationCultivation.materialQuantity, propagationCultivation.cultivateNumber, propagationCultivation.cultivateSubstance, propagationCultivation.cultivateDate, propagationCultivation.cultivateDate1, propagationCultivation.survive1, propagationCultivation.cultivateDate2, propagationCultivation.survive2, propagationCultivation.cultivateDate3, propagationCultivation.survive3, propagationCultivation.survivalRate, propagationCultivation.growthSituation, propagationCultivation.recorder, propagationCultivation.fillingDate };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(PLANT_CONSERVATION, propagationCultivation.plantConservation).map(INTRO_NO, propagationCultivation.introNo).map(MATERIAL_TYPE, propagationCultivation.materialType).map(MATERIAL_QUANTITY, propagationCultivation.materialQuantity).map(CULTIVATE_NUMBER, propagationCultivation.cultivateNumber).map(CULTIVATE_SUBSTANCE, propagationCultivation.cultivateSubstance).map(CULTIVATE_DATE, propagationCultivation.cultivateDate).map(CULTIVATE_DATE_1, propagationCultivation.cultivateDate1).map(SURVIVE_1, propagationCultivation.survive1).map(CULTIVATE_DATE_2, propagationCultivation.cultivateDate2).map(SURVIVE_2, propagationCultivation.survive2).map(CULTIVATE_DATE_3, propagationCultivation.cultivateDate3).map(SURVIVE_3, propagationCultivation.survive3).map(SURVIVAL_RATE, propagationCultivation.survivalRate).map(GROWTH_SITUATION, propagationCultivation.growthSituation).map(RECORDER, propagationCultivation.recorder).map(FILLING_DATE, propagationCultivation.fillingDate);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, propagationCultivation);
    }
}
